package com.investmenttechnologyservices.model;

import java.util.Currency;
import java.util.Date;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
/**
 * HolidayDate can be assigned by region, by Exchange or Currency
 * Region and Currency are used for cash settlement, Exchange for trading
 * 
 * @author david.goodman
 *
 */
public class HolidayDate extends EntityHolder {
	//@Id 
	//private Long key;
	//@NotSaved(IfDefault.class)
	//private Key<Region> regionKey;
	//@NotSaved(IfDefault.class)
	//private Key<Exchange> exchangeKey;
	//@NotSaved(IfDefault.class)
	//private Currency currency;
	
	//private String holidayDate;
	//private Boolean repeatYearly = true;
	//private Boolean moveToMonday = true;
	
	public HolidayDate(Entity entity) {
		super(entity);
	}
	
	public HolidayDate(String kind) {
		super(kind);
	}
	
	public HolidayDate(Key key, Date holidayDate, Boolean repeatYearly, Boolean moveToMonday) {
		super("holidayDate");
		if (key.getKind() == "region"){
			setRegionKey(key);
	    }
	    else if (key.getKind()=="exchange"){
			setExchangeKey(key);
	    } else if (key.getKind()=="bank") {
	    	setBankKey(key);
	    }
		setHolidayDate(holidayDate);
		setRepeatYearly(repeatYearly);
		setMoveToMonday(moveToMonday);
	}
	
	public HolidayDate(Key key, Date holidayDate) {
		this(key, holidayDate, null, null);
	}
	
	public HolidayDate(Currency currency, Date holidayDate, Boolean repeatYearly, Boolean moveToMonday) {
		super("holidayDate");
		setCurrency(currency);
		setHolidayDate(holidayDate);
		setRepeatYearly(repeatYearly);
		setMoveToMonday(moveToMonday);
	}
	
	public Key getRegionKey() {
		return (Key)getProperty("region");
	}
	
	public void setRegionKey(Key regionKey) {
		setProperty("regionKey",regionKey);
	}

	public Key getExchangeKey() {
		return (Key)getProperty("exchangeKey");
	}
	
	public void setExchangeKey(Key exchangeKey) {
		setProperty("exchangeKey",exchangeKey);
	}


	public Key getBankKey() {
		return (Key)getProperty("bankKey");
	}
	
	public void setBankKey(Key bankKey) {
		setProperty("bankKey",bankKey);
	}

	public Currency getCurrency() {return (Currency)getProperty("currency");}
	public void setCurrency(Currency currency) {setProperty("currency",currency);}
	
	public Date getHolidayDate() {
		return ((Date)getProperty("holidayDate"));
	}
	
	public void setHolidayDate(Date holidayDate) {
		setProperty("holidayDate",holidayDate);
	}
	
	public Boolean getRepeatYearly() {
		Boolean repeatYearly = (Boolean) getProperty("repeatYearly");
		if (repeatYearly == null) {
			repeatYearly = true;
		}
		return repeatYearly;
	}
	public void setRepeatYearly(Boolean repeatYearly) {
		if (repeatYearly != null && repeatYearly == false) {
			setProperty("repeatYearly", repeatYearly);
		}
	}
	
	public Boolean getMoveToMonday() {
		Boolean moveToMonday = (Boolean) getProperty("moveToMonday");
		if (moveToMonday == null) {
			moveToMonday = true;
		}
		return moveToMonday;
	}
	public void setMoveToMonday(Boolean moveToMonday) {
		if (moveToMonday != null && moveToMonday == false) {
			setProperty("moveToMonday", moveToMonday);
		}
	}

	@Override
	public String toString() {
		return "HolidayDate [holidayDate=" + getHolidayDate().toString() + 
				((getRegionKey()!=null)?", regionKey=" + getRegionKey().toString():"") +
				((getExchangeKey()!=null)?", exchangeKey=" + getExchangeKey().toString():"") +
				((getBankKey()!=null)?", bankKey=" + getBankKey().toString():"") +
				", repeatYearly=" + getRepeatYearly().toString() + 
				", moveToMonday="+getMoveToMonday().toString()+"]";
	}

	
}
